package com.ruoyi.base.service.impl;

import java.util.List;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.base.domain.Subject;
import com.ruoyi.base.domain.dto.SubjectReqDto;
import com.ruoyi.base.mapper.SubjectMapper;
import com.ruoyi.base.service.ISubjectService;
import com.ruoyi.common.core.utils.number.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;


/**
 * 科目管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-02-21
 */
@Service
public class SubjectServiceImpl extends ServiceImpl<SubjectMapper,Subject> implements ISubjectService
{
    @Autowired
    private SubjectMapper financialSubjectMapper;

    /**
     * 查询科目管理
     * 
     * @param id 科目管理主键
     * @return 科目管理
     */
    @Override
    public Subject selectFinancialSubjectById(Long id)
    {
        return financialSubjectMapper.selectSubjectById(id);
    }

    /**
     * 查询科目管理列表
     * 
     * @param financialSubject 科目管理
     * @return 科目管理
     */
    @Override
    public List<Subject> selectFinancialSubjectList(Subject financialSubject)
    {
        return financialSubjectMapper.selectSubjectList(financialSubject);
    }

    /**
     * 新增科目管理
     * 
     * @param financialSubject 科目管理
     * @return 结果
     */
    @Override
    public int insertFinancialSubject(Subject financialSubject)
    {
        return financialSubjectMapper.insert(financialSubject);
    }

    /**
     * 修改科目管理
     * 
     * @param financialSubject 科目管理
     * @return 结果
     */
    @Override
    public int updateFinancialSubject(Subject financialSubject)
    {
        return financialSubjectMapper.updateById(financialSubject);
    }

    /**
     * 批量删除科目管理
     * 
     * @param ids 需要删除的科目管理主键
     * @return 结果
     */
    @Override
    public int deleteFinancialSubjectByIds(Long[] ids)
    {
        return financialSubjectMapper.deleteSubjectByIds(ids);
    }

    /**
     * 删除科目管理信息
     * 
     * @param id 科目管理主键
     * @return 结果
     */
    @Override
    public int deleteFinancialSubjectById(Long id)
    {
        return financialSubjectMapper.deleteSubjectById(id);
    }

    /**
    * @Description: 查询科目列表
    * @Param: [subjectReqDto]
    * @return: java.util.List<com.ruoyi.base.domain.Subject>
    * @Author: Yuan
    * @Date: 2025/2/25
    */
    @Override
    public List<Subject> selectSubjectList(SubjectReqDto subjectReqDto) {
        Subject subject = new Subject();
        if (subjectReqDto.getSubjectType() != null) {
            subject.setSubjectType(subjectReqDto.getSubjectType());
        }
        if (subjectReqDto.getValues() != null) {
            if (NumberUtils.isNumberString(subjectReqDto.getValues())) {
                subject.setCode(subjectReqDto.getValues());
            } else {
                subject.setName(subjectReqDto.getValues());
            }
        }
        return financialSubjectMapper.selectSubjectList(subject);
    }
}
